//
//  CZVisitorViewController.swift
//  Weibo27
//
//  Created by apple on 16/4/16.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZVisitorViewController: UITableViewController {
    
    
    
    // 判断用户是否登录标识
    var isLogin:Bool = CZUserAccountTools.sharedTools.isLogin
    // 访客视图
    var visitorView: CZVisitorView?
    
    
    override func loadView() {
        // 通过三目运算符
        isLogin ? super.loadView() : setupVisitorView()
        
//        if isLogin{
//            super.loadView()
//            
//        }else{
//            setupVisitorView()
//            
//        }
        
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    // MARK: -  监听事件
    @objc private func login(){
        let oauthVc = CZOAuthViewController()
        presentViewController(UINavigationController(rootViewController: oauthVc), animated: true, completion: nil)
        
    }
    // MARK: - 导航栏相关设置
    private func setupNav(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "login")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "login")
        
    }
    
    // MARK: -  设置视图
    private func setupVisitorView(){
        setupNav()
        visitorView = CZVisitorView()
        visitorView?.visitorClosure = {
            self.login()
        }
        view = visitorView
    }

}
